#ifndef __VVIEW_VEVENTTEST_H__
#define __VVIEW_VEVENTTEST_H__

#include "../VView/common/vEventHelper.h"
using namespace vview;

DECLARE_EVENT(void, EVENT_ONPROCESS)(int nPercent);

class CRunner
{
public:
	void Run()
	{
		int nTime = 0;
		while ((nTime++) < 100)
		{
			Sleep(10);
			if (EVENT_ASSIGNED(OnProcess))
				INVOKE_EVENT(OnProcess, EVENT_ONPROCESS)(nTime);
		}
	}

public:
	CEventMethod OnProcess;
};

class CRunShow
{
private:
	int m_Percent;
	CRunner* m_pRunner;

public:
	CRunShow(): m_Percent(0), m_pRunner(NULL) {}

	void RunProcess(int nPercent)
	{
		V_TRACEA("previous is %d and now is %d\n", m_Percent, nPercent);
		m_Percent = nPercent;

		if ((NULL != m_pRunner) && (m_Percent == 50))
			CLEAR_EVENT(m_pRunner->OnProcess);
	}

	void InitEvent(CRunner& R)
	{
		m_pRunner = &R;
		R.OnProcess = MAKE_EVENT(this, &CRunShow::RunProcess);
	}
};

WINX_SIMPLE_TEST(TestEvent)
{
	{
		CRunner runner;
		CRunShow runshow;
		runner.OnProcess = MAKE_EVENT(&runshow, &CRunShow::RunProcess);
		runner.Run();
	}

	{
		CRunner runner2;
		CRunShow runshow2;
		runshow2.InitEvent(runner2);
		runner2.Run();
	}
}

#endif // __VVIEW_VEVENTTEST_H__